//
//  Kylin_TabBarController.m
//  03-BuDeJie-2 TabBar设置
//
//  Created by Kylin on 16/1/29.
//  Copyright © 2016年 kylin. All rights reserved.
//

#import "Kylin_TabBarController.h"
#import "Kylin_EssenceViewController.h"
#import "Kylin_FriendTrendsViewController.h"
#import "Kylin_MeViewController.h"
#import "Kylin_NewViewController.h"
#import "Kylin_TabBar.h"
#import "Kylin_NavgationViewController.h"

@implementation Kylin_TabBarController


- (void)viewDidLoad{
    [super viewDidLoad];
    
    [self setItem];
    [self setUpChildVC];
    
    // 添加自已的 tabBar
    [self setupTabBar];
   
}


- (void)setupTabBar{
    // 注意点,能过KVC 可以获取到UITabBarController 的和私有成员属性
    [self setValue:[[Kylin_TabBar alloc]init] forKeyPath:@"tabBar"];
    
}
#pragma mark-  添加TABBAR控制器
- (void)setUpChildVC{
    

    
    [self setUpChildVC:[[Kylin_EssenceViewController alloc]init] title:@"精华" image:@"tabBar_essence_icon" selectedImage:@"tabBar_essence_click_icon"];
    
    [self setUpChildVC:[[Kylin_NewViewController alloc]init] title:@"新贴" image:@"tabBar_new_icon" selectedImage:@"tabBar_new_click_icon"];
    
    [self setUpChildVC:[[Kylin_FriendTrendsViewController alloc]init] title:@"关注" image:@"tabBar_friendTrends_icon" selectedImage:@"tabBar_friendTrends_click_icon"];
    
    [self setUpChildVC:[[Kylin_MeViewController alloc]initWithStyle:UITableViewStyleGrouped] title:@"我的" image:@"tabBar_me_icon" selectedImage:@"tabBar_me_click_icon"];
    
    
}

#pragma mark- 添加一个子控制
- (void)setUpChildVC:(UIViewController *)vc title:(NSString *)title image:(NSString *)image selectedImage:(NSString *)selectedImage{
    
    
    // 取出传送过来的VC 设置为导航栏
    Kylin_NavgationViewController *nav = [[Kylin_NavgationViewController alloc]initWithRootViewController:vc];
    
    // 加入到TABBAR当前去
    [self addChildViewController:nav];
    
    nav.tabBarItem.title = title;
    nav.tabBarItem.image = [UIImage imageNamed:image];
    nav.tabBarItem.selectedImage = [UIImage imageNamed:selectedImage];
    
    
}

#pragma mark- 统一设置所有导航栏属性
- (void)setItem{
    
    // 设置正常状态下的属性
    NSMutableDictionary *normalAttribute = [NSMutableDictionary dictionary];
    normalAttribute[NSForegroundColorAttributeName] = [UIColor grayColor];
    normalAttribute[NSFontAttributeName] = [UIFont systemFontOfSize:12];
    
    // 设置选中状态下的属性
    NSMutableDictionary *selectedAttribute = [NSMutableDictionary dictionary];
    selectedAttribute[NSForegroundColorAttributeName] = [UIColor darkGrayColor];
    
    // 统一线所有的UItabBarItem 文字设置颜色
    UITabBarItem *item = [UITabBarItem appearance];
    [item setTitleTextAttributes:normalAttribute forState:UIControlStateNormal];
    [item setTitleTextAttributes:selectedAttribute forState:UIControlStateSelected];
    
    
}

@end
